//
// Created on 24/10/12.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef MOONLIGHT_OHOS_XCOMPONENTUTILS_H
#define MOONLIGHT_OHOS_XCOMPONENTUTILS_H

#include <napi/native_api.h>
#include <ace/xcomponent/native_interface_xcomponent.h>

#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN  0x0
#define LOG_TAG     "XComponentUtils"
#include <hilog/log.h>

#include <string>
#include <optional>


#define XCOMP_CALL_OR_ELSE(expr, otherwise) \
    if (auto xcompCallResult = OH_NativeXComponent_##expr; xcompCallResult != OH_NATIVEXCOMPONENT_RESULT_SUCCESS) { \
        OH_LOG_ERROR(LOG_APP, "XComponent call %{public}s failed with %{public}d", #expr, xcompCallResult); \
        otherwise; \
    }

#define XCOMP_RETURN_IF_NOT_OK(r, expr) \
    XCOMP_CALL_OR_ELSE(expr, return r)

struct XComponentUtils {

    static std::optional<std::string> getId(OH_NativeXComponent *comp);

};

#endif //MOONLIGHT_OHOS_XCOMPONENTUTILS_H
